package com.phone.servlet;

import com.phone.ParameterCheck;
import com.phone.exception.ErrorCode;
import com.phone.exception.ErrorException;
import org.hibernate.Session;
import org.json.JSONObject;

import javax.servlet.annotation.WebServlet;

/**
 * Created by tisen on 2017/9/26.
 */
@WebServlet(name = "Account", urlPatterns = "/account")
public class AccountServlet extends SuperServlet {
    private static final String LOGOUT = "logout";
    private static final String FORGET_PASSWORD = "forget_password";
    private static final String RESET_PASSWORD = "reset_password";
    private static final String UNBIND_WX = "unbind_wx";
    private static final String UNBIND_QQ = "unbind_qq";
    private static final String UNBIND_PHONE = "unbind_phone";
    private static final String BIND_PHONE = "bind_phone";
    private static final String BIND_WX = "bind_wx";
    private static final String BIND_QQ = "bind_qq";


    @Override
    protected JSONObject Control(ParameterCheck check, Session session) throws Exception {
        JSONObject jsonObject = new JSONObject();

        String action = check.getParameterString(ACTION, false);
        switch (action) {
            case LOGOUT:
                jsonObject = logout(check, session);
                break;
            case FORGET_PASSWORD:
                jsonObject = forget_password(check, session);
                break;
            case RESET_PASSWORD:
                jsonObject = reset_password(check, session);
                break;
            case UNBIND_WX:
                jsonObject = unbind_wx(check, session);
                break;
            case UNBIND_QQ:
                jsonObject = unbind_qq(check, session);
                break;
            case UNBIND_PHONE:
                jsonObject = unbind_phone(check, session);
                break;
            case BIND_PHONE:
                jsonObject = bind_phone(check, session);
                break;
            case BIND_WX:
                jsonObject = bind_wx(check, session);
                break;
            case BIND_QQ:
                jsonObject = bind_qq(check, session);
                break;
            default:
                throw new ErrorException(ErrorCode.UN_DEFINED_ACTION);
        }

        return jsonObject;
    }

    private JSONObject bind_qq(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject bind_wx(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject bind_phone(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject unbind_phone(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject unbind_qq(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject unbind_wx(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject reset_password(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject forget_password(ParameterCheck check, Session session) {
        return null;
    }

    private JSONObject logout(ParameterCheck check, Session session) {
        return null;
    }
}
